#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <time.h>

class LogPid {
        public:
                LogPid() {
                }
                ~LogPid() {
                }
                static void printPID(const WORD &serverid, const std::string &filename = "/log/ct_proc_server_map.log") {
                        std::string timestr;
                        time_t t;
                        time(&t);
                        struct tm gt;
                        struct tm *p = NULL;
                        p = localtime_r(&t, &gt);
                        if(NULL != p) {
                                char buf[256] = {0};
                                snprintf(buf, sizeof(buf)-1, "%.4d%.2d%.2d-%.2d:%.2d:%.2d",
                                                p->tm_year+1900,
                                                p->tm_mon + 1,
                                                p->tm_mday,
                                                p->tm_hour, 
                                                p->tm_min,
                                                p->tm_sec);
                                timestr = buf;
                        }
                        else {
                                return;
                        }

                        char cmd[1024] = {0};
                        snprintf(cmd, sizeof(cmd)-1, "echo '%s\t%u\t%u' >> %s",
                                        timestr.c_str(), getpid(), serverid, filename.c_str());
                        system(cmd);
                }
};
